$(document).ready(function(){
$('#role_button').click(function() {
	var role_id = $('select[name=role_id]').val();
	if (role_id == 0) {
		alert('请选择一个角色!');
	} else {
		window.location = '/priv/redit/' + role_id;
	}
});

$('#redit_info_form').submit(function() {
	var role = $('input[name=role]').val();
	var remark = $('textarea[name=remark]').val();

	var role_flag = true;
	$('#role').focus(function() {
		$('#role_msg').empty();
	});
	if(role.toString().length == 0) {
		$('#role_msg').html('<span style="color:red;">角色名不能为空</span>');
		role_flag = false;
	}

	if (role_flag) {
		$.post('/priv/redit_info', $('#redit_info_form').serialize(), function(data){
					if (data.r == 'succ') {
						alert('操作成功');
					} else {
						alert('操作失败' +  "\n>" +  data.msg.join("\n>"));
					}
				}, 'json');
	}
	return false;
});

$('input.priv').click(function() {
	if ($(this).attr('checked') == 'checked') {
		var p = $(this).val() + '_a';
		$.post('/priv/redit_priv', {'priv':p}, function(data){
			if (data.r == 'succ') {
				//alert('操作成功');
			} else {
				alert('操作失败' +  "\n>" +  data.msg.join("\n>"));
				$(this).removeAttr('checked');
			}
		}, 'json');
	} else {
		var p = $(this).val() + '_d';
		$.post('/priv/redit_priv', {'priv':p}, function(data){
			if (data.r == 'succ') {
				//alert('操作成功');
			} else {
				alert('操作失败' +  "\n>" +  data.msg.join("\n>"));
				$(this).attr('checked', 'checked');
			}
		}, 'json');
	}
});

});
